package com.company.Sort2;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}21:03
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {1,5,8,4,2,6};
        System.out.println(Arrays.toString(Bsort(arr)));
    }
    public static int[] Bsort(int[] arr){
        int temp;
        boolean flag = false;
        for (int i = 0; i < arr.length; i++){
            temp = 0;
            for (int j = 0; j < arr.length-1; j++){
                if (arr[j] > arr[j+1]){
                    flag = true;
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
            if (!flag){
                break;
            }else {
                flag = false;//重置flag
            }
        }
        return arr;
    }
}
